<template>
  <div>
    <!-- <h1>首页</h1> -->
    <!-- template插槽方式,表单中的输入框组件 -->
    <van-nav-bar class="nav">
      <template #left>
        <van-field
          class="input-el"
          left-icon="search"
          right-icon="scan"
          placeholder="影视 图书 唱片 小组等"
        />
        <img src="../pages/img/03.png" class="img" />
      </template>
    </van-nav-bar>
    <!-- 轮播图 axios请求图片地址-->
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img :src="image" class="swiper-img" />
      </van-swipe-item>
    </van-swipe>
    <!-- 列表 -->
    <div class="list" v-for="(item,index) in list" :key="index">
      <div class="left">
        <div class="title">{{item.title}}</div>
        <div class="text">{{item.target.desc}}</div>
        <div class="name">作者:{{item.target.author.name}}</div>
      </div>
      <div class="right">
        <div>
          <img :src="item.target.url" class="item-img" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// src文件夹的index.js文件直接获取;
import http from '../api';
// import axios from 'axios';
export default {
  data() {
    return {
      // images: [],
      images: [
        'static/images/swipers/01.jpg',
        'static/images/swipers/02.jpg',
        'static/images/swipers/03.jpg'
      ],
      list: []
    };
  },
  // 自己封装的接口
  mounted() {
    // 轮播图post接口
    // http.getSwipers().then(res => {
    //   this.images = res.swiperImgs;
    // });

    // 轮播图get接口
    // http.getSwipers().then(res => {
    //   this.images = res.swiperImgs;
    //   console.log(this.images);
    // });
    // 列表的接口
    http.homeList().then(res => {
      this.list = res.recommend_feeds;
    });
  }
  // axios自己获取的数据
  // mounted() {
  //   // 解决跨域,用封装过的地址,获取轮播图-图片地址;
  //   axios.post('/api/swipers', {}).then(res => {
  //     console.log(res.data.swiperImgs);
  //     this.images = res.data.swiperImgs;
  //     console.log(this.imgs);
  //   });
  //   // 本地获取列表,标题,内容;
  //   axios.get('static/data/homeData.json', {}).then(res => {
  //     // 打印一下
  //     console.log(res.data.recommend_feeds);
  //     // 给data里面的空数组赋值
  //     // this.list=res.data.数据;
  //     this.list = res.data.recommend_feeds;
  //   });
  // }
};
</script>
<style scoped>
.nav {
  height: 3rem;
  width: 37.5rem;
  display: flex;
  position: sticky;
  top: 0;
  align-items: center;
  background-color: rgb(72, 189, 90);
}
.input-el {
  width: 30rem;
  height: 1.8rem;
  display: flex;
  align-items: center;
  border-radius: 0.3rem;
}

.img {
  margin-left: 2rem;
  background-color: rgb(72, 189, 90);
  width: 2rem;
  height: 1.8rem;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #04aa44;
}
.swiper-img {
  width: 38rem;
  height: 15rem;
}
/* 列表样式 */
.list {
  display: flex;
  flex-direction: row;
  margin: 0.9rem 0;
  background-color: whitesmoke;
  opacity: 0.6;
  justify-content: space-between;
  border: 1px solid white;
  padding: 1.2rem;
}
.title {
  font-weight: 600;
  font-size: 1.7em;
  font-family: '黑体';
  /* 控制字体之间的距离css属性 */
  letter-spacing: 0.15rem;
  color: rgba(24, 22, 22, 0.8);
  /* 词语,单词之间的间距 */
  /* word-spacing: 10px; */
}
.text {
  font-size: 1.8rem;
  color: gray;
  margin: 0.3rem 0;
}
.name {
  font-size: 1.3rem;
  margin-top: 0.2rem;
  color: gray;
}
.item-img {
  width: 10rem;
  height: 10rem;
}
.left {
  display: flex;
  flex-direction: column;
  /* justify-content: space-around; */
  /* align-items: center; */
}
</style>